﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using Intelligent.OTC.Common;
using Intelligent.OTC.Common.Repository;
using Intelligent.OTC.Domain.DataModel;

namespace Intelligent.OTC.Business
{
    public class ApiMailer: IMailer
    {
        public void MarkAsRead(string mailBox, string msgId)
        {
            MailServiceProxy proxy = new MailServiceProxy(ConfigurationManager.AppSettings["MailserviceEndPoint"]);
            proxy.MarkAsRead(mailBox, msgId);
        }

        public List<MailRaw> GetMailRaw(string mailBox, long lastMsgTime)
        {
            MailServiceProxy proxy = new MailServiceProxy(ConfigurationManager.AppSettings["MailserviceEndPoint"]);
            List<MailRaw> raws = new List<MailRaw>();
            raws = proxy.GetMailRaw(mailBox, lastMsgTime);

            return raws;
        }

        public bool SendMailRaw(MailRaw rawMessage)
        {
            if (ConfigurationManager.AppSettings["IsMail"] == "true")
            {
                MailServiceProxy proxy = new MailServiceProxy(ConfigurationManager.AppSettings["MailserviceEndPoint"]);
                return proxy.SendMailRaw(rawMessage);
            }
            else
            {
                return true;
            }
        }

        public bool CheckMailBoxInitialized(string userMailBox)
        {
            MailServiceProxy proxy = new MailServiceProxy(ConfigurationManager.AppSettings["MailserviceEndPoint"]);
            return proxy.CheckMailBoxInitialized(userMailBox);
        }
    }
}
